package com.kaitian.demo.demo_boot_starter.plugin;

import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Plugin;
import org.apache.ibatis.plugin.Signature;

import java.sql.Connection;
import java.util.Properties;

/**
 * @author ：xietian
 * @version ：V1.0
 * @program ：demo
 * @date ：Created in 2022/4/8 13:42
 * @description ：Mybatis通用拦截器/插件
 */
@Intercepts(
    @Signature(
        type = StatementHandler.class,
        method = "prepare",
        args = {
            Connection.class,
            Integer.class
        }
    )
)
public class MyBatisPlugin implements Interceptor {

    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        // 插件拦截器方法
        return invocation.proceed();
    }

    @Override
    public Object plugin(Object target) {
        // 生成MyBatis拦截器代理对象
        return Plugin.wrap(target, this);
    }

    @Override
    public void setProperties(Properties properties) {
        // 设置插件属性
    }
}